/**
 * Copyright 2006-2017 the original author or authors.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.mybatis.generator.codegen.mybatis3.javamapper.elements;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.dom.java.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

/**
 *
 * @author Jeff Butler
 *
 */
public class FindAllMethodGenerator extends AbstractJavaMapperMethodGenerator {

    private boolean isSimple;

    public FindAllMethodGenerator(boolean isSimple) {
        super();
    }

    @Override
    public void addInterfaceElements(Interface interfaze) {
        Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
        importedTypes.add(new FullyQualifiedJavaType("java.util.List"));
        importedTypes.add(new FullyQualifiedJavaType("java.util.Map"));
        Method method = new Method();
        method.addJavaDocLine("/**\n\t * Desc: 列表页数据\n\t * @author "+System.getProperty("user.name")+"\n\t * @param param 查询条件\n\t * @return 返回列表数据\n\t * Date :"+new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss").format(new Date())+"\n\t */");
        method.setVisibility(JavaVisibility.PUBLIC);

        FullyQualifiedJavaType returnType = new FullyQualifiedJavaType("List<"+introspectedTable.getRules().calculateAllFieldsClass()+">");
        method.setReturnType(returnType);
        importedTypes.add(returnType);
        method.setName(introspectedTable.getFindAllStatementId());


        method.addParameter(new Parameter(new FullyQualifiedJavaType("Map<String, Object>"),"param"));
        addMapperAnnotations(interfaze, method);

        context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
        if (context.getPlugins().clientSelectByPrimaryKeyMethodGenerated(method, interfaze, introspectedTable)) {
            addExtraImports(interfaze);
            interfaze.addImportedTypes(importedTypes);
            interfaze.addMethod(method);
        }
    }

    public void addMapperAnnotations(Interface interfaze, Method method) {
    }

    public void addExtraImports(Interface interfaze) {
    }
}
